package com.jsj.controller;

import com.jsj.domain.Course;
import com.jsj.domain.StuClass;
import com.jsj.service.CourseService;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/course")
public class CourseController {
    private CourseService courseService;

    @Autowired
    public void setCourseService(CourseService courseService) {
        this.courseService = courseService;
    }

    /**
     * 查询课程信息
     */
    @RequestMapping(value = "/query", method = {RequestMethod.POST})
    @ResponseBody
    @PreAuthorize("@ss.hasAnyRoles('student,teacher,admin')")
    public List<Course> query() {
        startPage();
        return courseService.query();
    }

    /**
     * 查询教师课程信息
     */
    @RequestMapping(value = "/queryByTeacher/{teacherId}", method = {RequestMethod.POST})
    @ResponseBody
    @PreAuthorize("@ss.hasAnyRoles('teacher,admin')")
    public List<Course> queryByTeacher(@PathVariable("teacherId") String teacherId) {
        startPage();
        return courseService.queryByTeacher(teacherId);
    }

    /**
     * 查询学生课程信息
     */
    @RequestMapping(value = "/queryByStudent/{studentId}", method = {RequestMethod.POST})
    @ResponseBody
    @PreAuthorize("@ss.hasAnyRoles('student,teacher,admin')")
    public List<Course> queryByStudent(@PathVariable("studentId") String studentId) {
        return courseService.queryByStudent(studentId);
    }
    /**
     * 创建课程
     */
    @RequestMapping(value = "/insert", method = {RequestMethod.POST})
    @ResponseBody
    @PreAuthorize("@ss.hasAnyRoles('teacher,admin')")
    public AjaxResult insert(@RequestBody Course course) {
        if (courseService.insert(course) == 0) {
            return AjaxResult.error("创建课程失败");
        }
        return AjaxResult.success("创建课程成功");
    }

}
